Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added temporary voice messages #1874

Merged
merged 3 commits into from
Dec 18, 2024
Merged

Conversation

DanielStandfest
Copy link
Contributor

added support for temporary voice messages and handling them just like text messages.

related to #1261

Would be happy to get feedback! :)

Cheers,
Daniel

@DanielStandfest DanielStandfest force-pushed the better-voice-message-handling branch 3 times, most recently from c44beda to dd3e20b Compare November 11, 2024 19:20
@DanielStandfest
Copy link
Contributor Author

I am not sure why the localizable change is not passing the test? :/

@SystemKeeper
Copy link
Collaborator

I am not sure why the localizable change is not passing the test? :/

Interesting, seems to be a sorting issue. I’ll take a look.

@SystemKeeper
Copy link
Collaborator

I’ll take a look.

So I tried multiple things yesterday and it only happens if you rebase on master (that is what CI does and that's why you can't seem to trigger that change locally in your branch). I have the same issue in #1880. I couldn't fully figure out what's triggering this, even rebasing on old commits did not change that. So for now I'd say we ignore it and take a look later when the PR is merged.

We are going to have a closer look to this and your other PR this week :)

Copy link
Collaborator

@SystemKeeper SystemKeeper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked through everything, here are some first comments :)


let referenceId = "temp-\(Date().timeIntervalSince1970 * 1000)"
temporaryMessage.referenceId = NCUtils.sha1(fromString: referenceId)
temporaryMessage.internalId = referenceId
temporaryMessage.isTemporary = true
temporaryMessage.isOfflineMessage = true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isOfflineMessage indicates that this message was sent without an internet connection and should be resend, when connection is available again. So this shouldn't be added here.
There's quite some logic involved (including trying to resend in the background). Check out e.g.

- (void)sendChatMessage:(NSString *)message replyTo:(NSInteger)replyTo referenceId:(NSString *)referenceId silently:(BOOL)silently

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the information, I recognized that the context menu fits better when using the isOfflineMessage = true. That's why I set it to true.
For example the "open in nextcloud" (shouldn't really be an option), "copy" and "create reminder" option dont work out of the box.

I removed it now, should we fix some of the options like "delete" then or hide some of the invalid options?

NextcloudTalk/BaseChatViewController.swift Show resolved Hide resolved
NextcloudTalk/BaseChatViewController.swift Outdated Show resolved Hide resolved
NextcloudTalk/BaseChatViewController.swift Outdated Show resolved Hide resolved
"fileLocalPath": messageParameters
]

messageParametersDict[parameterId] = fileParameterDict
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using a UUID here? Should it be the file dictionary? I don't see it used anywhere? (Maybe I missed it, not yet through everything).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I guess I had a problem with the file parameter not being set when putting the fileParameters in no dictionary.
What's your suggestion?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use "file" as the key here

Copy link

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@SystemKeeper
Copy link
Collaborator

Hey Daniel, left you a message about this PR on our instance :)

@@ -1590,52 +1634,83 @@ import QuickLook
audioFileName += ".mp3"

let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
NCAPIController.sharedInstance().setupNCCommunication(for: activeAccount)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a reason to setup the communication here? Because in uniqueNameForFileUploadWithName there's already a setup call and I don't think it's needed before that call.

isVoiceMessage: true
)

chatFileController.setFileStatusFrom(temporaryMessage.file())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are not using the chatFileController in this method again (besides moving the file), we don't need the filestatus to be set.

chatFileController.setFileStatusFrom(temporaryMessage.file())

let movedFileToTemporaryDirectory = chatFileController.moveFileToTemporaryDirectory(
fromSourcePath: self.recorder!.url.path,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use something like guard let recorder = self.recorder else { return } at the beginning of the file, so we don't have to force-unwrap here.

NCAPIController.sharedInstance().uniqueNameForFileUpload(withName: audioFileName, originalName: true, for: activeAccount, withCompletionBlock: { fileServerURL, fileServerPath, _, _ in
if let fileServerURL, let fileServerPath, let recorder = self.recorder {
let talkMetaData: [String: String] = ["messageType": "voice-message"]
self.uploadFileAtPath(localPath: recorder.url.path, withFileServerURL: fileServerURL, andFileServerPath: fileServerPath, withMetaData: talkMetaData)

self.uploadFileAtPath(localPath: recorder.url.path, withFileServerURL: fileServerURL, andFileServerPath: fileServerPath, withMetaData: talkMetaData, temporaryMessage: temporaryMessage)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.uploadFileAtPath(localPath: recorder.url.path, withFileServerURL: fileServerURL, andFileServerPath: fileServerPath, withMetaData: talkMetaData, temporaryMessage: temporaryMessage)
self.uploadFileAtPath(localPath: destinationFilePath, withFileServerURL: fileServerURL, andFileServerPath: fileServerPath, withMetaData: talkMetaData, temporaryMessage: temporaryMessage)

Otherwise the file is not found on upload (because we moved it before) and we get a 0 byte file.

completion(200, nil)
}
}
case 404:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original code, also case 409 was checked here.


- (void)initDownloadDirectoryForAccount:(TalkAccount *)account;
- (void)setFileStatusFromParameter:(NCMessageFileParameter *)fileParameter;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am not mistaken, this is not needed anymore, since we don't call it?!

Comment on lines 174 to 176
- (void)setFileStatusFromParameter:(NCMessageFileParameter *)fileParameter {
_fileStatus = [[NCChatFileStatus alloc] initWithFileId:fileParameter.parameterId fileName:fileParameter.name filePath:fileParameter.path fileLocalPath:fileParameter.fileStatus.fileLocalPath];
fileParameter.fileStatus = _fileStatus;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So also not needed?

NSError *error = nil;
if ([[NSFileManager defaultManager] moveItemAtPath:sourcePath toPath:destinationPath error:&error]) {
NSLog(@"File successfully moved to: %@", destinationPath);
_fileStatus.fileLocalPath = destinationPath;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the fileStatus is not used, we can remove that line as well

- (bool)moveFileToTemporaryDirectoryFromSourcePath:(NSString *)sourcePath destinationPath:(NSString *)destinationPath {
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];

[[NCAPIController sharedInstance] setupNCCommunicationForAccount:activeAccount];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to setup the communication here, as we only move locally.

"fileLocalPath": messageParameters
]

messageParametersDict[parameterId] = fileParameterDict
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use "file" as the key here

@DanielStandfest DanielStandfest force-pushed the better-voice-message-handling branch 3 times, most recently from 365e2c7 to b1797e5 Compare December 16, 2024 19:24
related to #1261

Signed-off-by: Daniel Standfest <[email protected]>
@DanielStandfest DanielStandfest force-pushed the better-voice-message-handling branch from c9964ad to 35aa953 Compare December 16, 2024 19:52
@DanielStandfest DanielStandfest enabled auto-merge (rebase) December 16, 2024 21:36
@DanielStandfest
Copy link
Contributor Author

Review implemented.

Copy link
Member

@Ivansss Ivansss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this PR @DanielStandfest :)
Works nicely now and it's a great enhancement!

auto-merge was automatically disabled December 17, 2024 14:58

Rebase failed

@SystemKeeper SystemKeeper merged commit b99ba37 into master Dec 18, 2024
11 checks passed
@SystemKeeper SystemKeeper deleted the better-voice-message-handling branch December 18, 2024 15:28
@SystemKeeper
Copy link
Collaborator

Thanks again @DanielStandfest ! Merged and will be included in the next release :)
Please remember to rebase instead of creating merge request though ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ☑️ Done
Development

Successfully merging this pull request may close these issues.

3 participants